import torch
from torch.autograd import Variable
import numpy as np

tensor = torch.FloatTensor([[1,2],[3,4]])
variable= Variable(tensor, requires_grad=True) #创建图纸，参数说明是否在计算反向传播时需要计算该点梯度

print(tensor)
print(variable)

t_out =torch.mean(tensor*tensor)
v_out=torch.mean(variable*variable)

v_out.backward()
print(variable.grad)
print(variable.data)